$(function() {
    var token = localStorage.token;
    if(!token) {
        location.href = "../loginAndReg/login.html";
        return false;
    }
    new FastClick(document.body);
    var score = 1;
    $(".commentTypeBtn").on("click",function(){
        var selectStatus = parseInt($(this).attr("data-select"));
        if(selectStatus===1) return false;
        score = parseInt($(this).attr("data-score"));
        if(score===0||score===-1) {
            $(".good").find("img").attr("src","../../static/img/good_unselected@3x.png");
            $(".normal").find("img").attr("src","../../static/img/bad_unselected@3x.png");
            $(".bad").find("img").attr("src","../../static/img/bad_unselected@3x.png");
            $(".commentTypeBtn").css("color","#c7c7c7");
            $(".commentTypeBtn").attr("data-select",0);            
            $(this).find("img").attr("src","../../static/img/bad_selected@3x.png");
            $(this).css("color","#ffa31a");
            $(this).attr("data-select",1)            
        }else if(score===1) {
            $(".normal").find("img").attr("src","../../static/img/bad_unselected@3x.png");
            $(".bad").find("img").attr("src","../../static/img/bad_unselected@3x.png");
            $(".commentTypeBtn").css("color","#c7c7c7");
            $(".commentTypeBtn").attr("data-select",0);
            $(this).find("img").attr("src","../../static/img/good_selected@3x.png");
            $(this).css("color","#ffa31a");
            $(this).attr("data-select",1)
        }
    });
    //提交评论
    $(".subBtn").on("click",function() {
        var id = tools.queryString().id;
        var skuId = tools.queryString().skuId;
        var message = $(".comment").val();
        $.ajax({
            type: "post",
            url: dimain.test + "/submitcomment",
            // url: dimain.online + "/order/review",
            data: {
                id:id,
                skuId:skuId,
                score:score,
                message:message,
                imgs:""
            },
            beforeSend: function (xhr) {
                xhr.setRequestHeader("tokne",token);
            },  
            success: function (response) {
                if(response.data.rtnCode===200) {
                // if(response.rtnCode===200) {
                    console.log(response);
                }
            }
        });
    });
});